package com.xiangxiao.rpan.storage.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2023/8/25 11:40
 */
@Component(value = "transferByCacheManager")
public class TransferByCacheManager implements TransferFileByCacheTool {
  @Autowired
  @Qualifier(value = "transferFileByCacheToolSelector")
  private TransferFileByCacheToolSelector transferFileByCacheToolSelector;

  @Override
  public void writeFileToStream(FileInputStream fileInputStream, FileOutputStream outputStream) {
    transferFileByCacheToolSelector.select().writeFileToStream(fileInputStream, outputStream);
  }

  @Override
  public void writeStreamToStreamNormal(InputStream inputStream, FileOutputStream outputStream) {
    transferFileByCacheToolSelector.select().writeStreamToStreamNormal(inputStream, outputStream);
  }

  @Override
  public String convertMuitlFileToStream(MultipartFile multipartFile, Integer chunkNumber, Integer totalChunks, long blockSize) {
    return transferFileByCacheToolSelector.select().convertMuitlFileToStream(multipartFile, chunkNumber, totalChunks, blockSize);
  }
}
